﻿using System;
using System.Web.UI;
using EntitiesTM;
using Business;

namespace TimeWork
{
    public partial class ChangePwd : System.Web.UI.Page
    {
        public string Email { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] != null)
            {
                try
                {
                    this.Email = Session["email"].ToString();
                    LbEmail.Text = Email;
                }
                catch { }
            }
            else
            {
                Response.Redirect("http://"+Request.Url.Authority+"/Login.aspx");
            }
        }

        protected void BtnUpdate_Click(object sender, EventArgs e)
        {
            LblNotice.Text = String.Empty;
            LblError.Text = String.Empty;

            EnStaff staff = new EnStaff();
            if (!TxtNewPass.Text.ToString().Equals(TxtNewPassConfirm.Text.ToString()))
            {
                LblError.Text = " Mật khẩu mới không trùng nhau!";
            }
            else
            {
                try
                {
                    staff.staffEmail = this.Email;
                    staff.staffPassword = TxtOldPass.Text.ToString();
                    string passNew = TxtNewPass.Text.ToString();
                    int result = BuStaff.UpdatePassword(staff, passNew, Session["companyid"].ToString());
                    if (result == 1)
                    {
                        LblNotice.Text = "Sai mật khẩu!";
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "alert('Đổi mật khẩu thành công!');location.href='MyProfile.aspx';", true);
                    }
                }
                catch
                {
                    // Loi nhap lieu
                }
            }
        }

        protected void BtnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("MyProfile.aspx");
        }
    }
}